package com.liyuxiang.controller;

import com.liyuxiang.exception.SystemException;
import com.liyuxiang.pojo.entity.User;
import com.liyuxiang.service.BlogLoginService;
import com.liyuxiang.vm.ResponseResult;
import com.liyuxiang.vm.enums.ResultStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        if (!StringUtils.hasText(user.getUserName())){
            throw new SystemException(ResultStatusEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        System.out.println("退出");
        return blogLoginService.logout();

    }
}
